﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using vjspider;

namespace ZMenFM.Network
{
    static public class ZMNetworkGlobal
    {
        static public const String FromVar = "ZMenFM";
        static protected bool Inited = false;
        static protected VJSpider ZMSpider;

        /// <summary>
        /// 获取爬虫对象
        /// </summary>
        /// <returns>爬虫对象</returns>
        static public VJSpider GetSpider()
        {
            if (!Inited)
            {
                try
                {
                    InitEnviroment();
                }
                catch(Exception e)
                {
                    return null;
                }
            }

            return ZMSpider;
        }

        /// <summary>
        /// 初始化环境
        /// </summary>
        static public void InitEnviroment()
        {
            ZMSpider = new VJSpider();

            if (!ZMSpider.InitContext())
            {
                Exception e = new Exception("ZMNetwork failed to initialize.");
                throw e;
            }

            Inited = true;
        }
    }
}
